import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs));
}

// Media-related helpers
export async function requestUserMediaStream(
  constraints: MediaStreamConstraints
): Promise<MediaStream> {
  if (!navigator?.mediaDevices?.getUserMedia) {
    throw new Error("当前浏览器不支持摄像头访问或已被策略禁用");
  }
  return await navigator.mediaDevices.getUserMedia(constraints);
}

export function isMediapipePoseAvailable(): boolean {
  return (
    typeof window !== "undefined" &&
    (window as any).Pose &&
    (window as any).Camera &&
    (window as any).drawConnectors &&
    (window as any).drawLandmarks &&
    (window as any).POSE_CONNECTIONS
  );
}

export type DisposeFn = () => void;
